﻿using LKVMLMLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Web.Mvc;

namespace TrucTiepService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "TrucTiepService" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select TrucTiepService.svc or TrucTiepService.svc.cs at the Solution Explorer and start debugging.
    public class TrucTiepService 
    {
        public TrucTiepThongConfig[] getlistTrucTiepAnhChuong()
        {
            string connection = DuAnDaCapEntities.getDomain();
            using (var db = TrucTiepEntities.initTrucTiepEntities(connection))
            {
                db.Configuration.ProxyCreationEnabled = false;
                return db.TrucTiepThongConfigs.ToArray();
            }      
        }
        public TrucTiepThongConfig getTrucTiepAnhChuong(int id)
        {
            string connection = DuAnDaCapEntities.getDomain();
            using (var db = TrucTiepEntities.initTrucTiepEntities(connection))
            {
                db.Configuration.ProxyCreationEnabled = false;
                return db.TrucTiepThongConfigs.Where(w => w.ID == id).FirstOrDefault();
            }   
        }
        public bool AddTrucTiepAnhChuong(TrucTiepThongConfig c)
        {
            bool result = false;
            string connection = DuAnDaCapEntities.getDomain();
            using (var db = TrucTiepEntities.initTrucTiepEntities(connection))
            {
                db.Configuration.ProxyCreationEnabled = false;
                db.TrucTiepThongConfigs.Add(c);
                db.SaveChanges();
                result = true;
            }
            return result;
        }
        public bool UpdateTrucTiepAnhChuong(TrucTiepThongConfig c)
        {
            bool result = false;
            string connection = DuAnDaCapEntities.getDomain();
            using (var db = TrucTiepEntities.initTrucTiepEntities(connection))
            {
                db.Configuration.ProxyCreationEnabled = false;
                var choose = db.TrucTiepThongConfigs.Where(w => w.ID == c.ID).FirstOrDefault();
                if(choose!=null)
                {
                    choose.Commission = c.Commission;
                    db.SaveChanges();
                    result = true;
                }
                
            }
            return result;
        }
        public bool RemoveTrucTiepAnhChuong(int id)
        {
            bool result = false;
            string connection = DuAnDaCapEntities.getDomain();
            using (var db = TrucTiepEntities.initTrucTiepEntities(connection))
            {
                db.Configuration.ProxyCreationEnabled = false;
                var choose = db.TrucTiepThongConfigs.Where(w => w.ID == id).FirstOrDefault();
                 if(choose!=null)
                 {
                     db.TrucTiepThongConfigs.Remove(choose);
                     db.SaveChanges();
                     result = true;
                 }                
            }
            return result;
        }
       
        /// <summary>
        /// get node root buy current user login
        /// </summary>
        /// 
        /// <param name="UserId"></param>
        /// <returns></returns>
       

        /// <summary>
        /// Get list children by 
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        

        
        
        
    }

    public class TriAnTree
    {
        public int UserId { get; set; }
        public string UserName { get; set; }
        public int? Child1 { get; set; }
        public int? Child2 { get; set; }
        public int? Child3 { get; set; }
        public int Pnode { get; set; }
        public int? Tang { get; set; }
        public bool Expand { get; set; }
        public int color { get; set; }
    }
}
